package com.stu.util;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Paths;
import java.util.Properties;

/**
 * @author zy
 * @date 2025/3/4 10:41
 */
public class ReadDBParamUtil {
    private static String filePath = "/conf/config.properties";
    private static Properties properties = new Properties();

    // 静态代码块只加载一次,减少io次数提高效率
    static {
        InputStream in = ReadDBParamUtil.class.getResourceAsStream(filePath);
        try {
            properties.load(in);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static String getDriverName(){
//        System.out.println(properties.getProperty("driverName"));
        return properties.getProperty("driverName");
    }
    public static String getUrl(){
//        System.out.println(properties.getProperty("url"));
        return properties.getProperty("url");
    }
    public static String getUserName(){
//        System.out.println(properties.getProperty("username"));
        return properties.getProperty("username");
    }
    public static String getPassword(){
//        System.out.println(properties.getProperty("password"));
        return properties.getProperty("password");
    }

    public static void main(String[] args) {
        getDriverName();
        getUrl();
        getUserName();
        getPassword();
    }
}
